package chapter14.core;

import javax.servlet.*;
import javax.servlet.http.*;


public class HttpContextHolder {
    private static ThreadLocal<HttpContext> threadLocal = new ThreadLocal<HttpContext>();

    public static void begin(HttpServletRequest request,
        HttpServletResponse response, ServletContext servletContext) {
        HttpContext httpContext = new HttpContext();
        httpContext.request = request;
        httpContext.response = response;
        httpContext.servletContext = servletContext;

        threadLocal.set(httpContext);
    }

    public static void after() {
        threadLocal.remove();
    }

    public static HttpContext get() {
        return threadLocal.get();
    }
}
